/*
 * 创建日期 2009-12-14
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.report;

import  org.fantasy.common.db.bean.ReportRow;
import  org.fantasy.common.grid.bean.Column;
import  org.fantasy.common.grid.bean.ReportParam;
import  org.fantasy.common.util.StringUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *  功能说明
 * @author: 王文成
 * @version: 1.0
 * @since 2009-12-14
 */
public class ReportListBuilder extends ReportHtmlBuilder {

    private static final Log log = LogFactory.getLog(ReportListBuilder.class);

    public ReportListBuilder(ReportParam param) throws Exception {
        super(param);
    }

    /**
     * 构造一行中的所有列
     * 
     * @return
     */
    @Override
    protected StringBuffer buildCells(ReportRow row) throws Exception {
        StringBuffer html = new StringBuffer(1024);
        for (int i = 0; i < tableFields.size(); i++) {
            Column col = tableFields.get(i);
            String colName = col.getId();
            String colValue = cellCustom.getValue(row, col);
            html.append("<td col='" + colName + "'");
            if ( StringUtil.isValid(col.getAlign()) )
                html.append(" align='" + col.getAlign() + "'");
            else if (col.isNumberType()) //默认数字居右
                html.append(" align='right'");

            // 是否显示
            if (param.isHideCol(col)){
                html.append(" style='display:none'");
            }else{ // 显示样式
                html.append(" " + getCellStyle(row,col) );
            }

            // 列宽
            if (StringUtil.isValid(col.getWidth()))
                html.append(" width='" + col.getWidth() + "'");
            else
                html.append(" nowrap='nowrap'");

            // 行高
            if (StringUtil.isValid(rowHeight))
                html.append(" height='" + rowHeight + "'");

            html.append(">");

            if (StringUtil.isValid(col.getClick())) {
                if (!(row.isSubTotal() || row.isSumTotal())) {
                    String onclick = getOnClickString(row, col.getClick());
                    html.append("<a href=\"javascript:" + onclick + "\" onclick='_StopBubble(event)'>");
                    html.append(colValue);
                    html.append("</a>");
                } else {
                    html.append(colValue);
                }
            } else {
                html.append(colValue);
            }
            html.append("</td>\n");
        }
        return html;
    }
}
